package cn.edu.lingnan.servlet;

import cn.edu.lingnan.pojo.Student;
import cn.edu.lingnan.service.IStudentService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/insertStu")
public class insertStuServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1
        String sid = req.getParameter("sid");
        String sname = req.getParameter("sname");
        String spassword = req.getParameter("password");
        String gender = req.getParameter("gender");
        String major = req.getParameter("major");
        String aclass = req.getParameter("class");
        Student student = new Student();
        student.setId(Integer.parseInt(sid));
        student.setName(sname);
        student.setPassword(spassword);
        student.setGender(gender);
        student.setMajor(major);
        student.setClassX(aclass);
        student.setRight(0);
        student.setFlag(0);
        //2
        IStudentService service = new IStudentService();
        System.out.println(student);
        service.addStudent(student);
        //3
        resp.sendRedirect(req.getContextPath()+"/index.html");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
